const express = require('express');
const router = express.Router();
const {
  regionListModel
} = require('../model/pickUpLocation')
const {
  categoryListModel,
  skuProductListModel
} = require('../model/product')
const {
  leaderAddressModel
} = require('../model/pickUpLocation')

/*
* 支付订单
*
* */
router.get('/payment/weixin/createJsapi/:orderNo', (req, res) => {
  res.send({
    code: 200,
    msg: '获取成功'
  })
});

/*
* 根据经纬度获取地址信息
*
* */
router.get('/sys/region/findAllList', async (req, res) => {
  const data = await regionListModel.find()
  res.send({
    code: 200,
    msg: '获取成功',
    data
  })
});

router.get('/search/leader/:page/:limit', async (req, res) => {
  const { limit, page, latitude, longitude } = req.query
  let skip = (page - 1) * limit
  const data = await leaderAddressModel.find().skip(skip).limit(limit)
  res.send({
    code: 200,
    msg: '获取成功',
    data: {
      content: data
    }
  })
});

router.get('/search/sku/:page/:limit', async (req, res) => {
  const { limit, page, categoryId } = req.query
  let skip = (page - 1) * limit
  const data = await skuProductListModel.find({ categoryId }).skip(skip).limit(limit)
  res.send({
    code: 200,
    msg: '获取成功',
    data: {
      content: data,
    }
  })
})

router.get('/user/leader/auth/selectLeader/:leaderId', (req, res) => {
  res.send({
    code: 200,
    msg: '获取成功'
  })
});

module.exports = router;
